/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package test;

import java.util.LinkedList;
import java.util.List;

/**
 *
 * @author xddai
 */
public class GetSubString {

    public static void main(String[] args) {
        String input = "A、AB、C、D、F,、GG、MM";
        for (String string : getSubString(input)) {
            System.out.println(string);
        }
        
        /*
         * 输出结果如下
         AB
         C
         D
         GG
         */
    }
/*
 * 此方法提取input中所有include符号(、)之间的内容，且内容中不能含有exclude中的字符串
 */
    public static String[] getSubString(String input) {
        String exclude = "，。？；！,;.";
        String include = "、";//提取include之间的内容，但内容中不能包含exclude中的字符
        char[] inputChars = input.toCharArray();
        List<String> output = new LinkedList<String>();
        String dempStr = "";
        int beginIdx = 0;
        boolean first = false;
        for (int i = 0; i < inputChars.length; i++) {
            if (include.indexOf(inputChars[i]) != -1) {
                if (first) {
                    dempStr = new String(inputChars, beginIdx + 1, i - beginIdx - 1);
                    output.add(dempStr);
                } else {
                    first = true;
                }
                beginIdx = i;
            }
            if (exclude.indexOf(inputChars[i]) != -1) {
                first = false;
            }

        }
        return output.toArray(new String[output.size()]);
    }
}
